package domain;


import FightLandlords.Common;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

public class Poker extends JLabel implements MouseListener {


    private String name;
    private boolean isUp;
    private boolean canClick = false;
    private boolean Clicked = false;

    public Poker(String name, boolean isUp) {

        this.name = name;
        this.isUp = isUp;

        //判断正面还是反面 添加图片
        is_Up();

        //设置宽高
        this.setSize(71, 96);
        //显示牌
        this.setVisible(true);
        //添加鼠标监听
        this.addMouseListener(this);
    }



    public void is_Up(){
        if (isUp) {
            //正面
            this.setIcon(new ImageIcon("E:\\practice-start\\java-test\\thelast\\image\\poker\\"+name+".png"));
        } else {
            //反面
            this.setIcon(new ImageIcon("E:\\practice-start\\java-test\\thelast\\image\\poker\\rear.png"));
        }
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        //移到像素数量
        int step = 0;

        //如果可以被点击
        if (canClick) {
            //判断是向上移到还是向下移到
            if (Clicked) {
                //向下
                step = 20;
            } else {
                //向上
                step = -20;
            }
            //改变状态
            Clicked = !Clicked;

            //获得当前牌的位置
            Point from = this.getLocation();
            //移到牌
            Point to = new Point(from.x,from.y+step);
            Common.move(this, from,to);
        }


    }

    @Override
    public void mousePressed(MouseEvent e) {

    }

    @Override
    public void mouseReleased(MouseEvent e) {

    }

    @Override
    public void mouseEntered(MouseEvent e) {

    }

    @Override
    public void mouseExited(MouseEvent e) {

    }

    /**
     * 获取
     *
     * @return name
     */
    public String getName() {
        return name;
    }

    /**
     * 设置
     *
     * @param name
     */
    public void setName(String name) {
        this.name = name;
    }

    /**
     * 获取
     *
     * @return isUp
     */
    public boolean isIsUp() {
        return isUp;
    }

    /**
     * 设置
     *
     * @param isUp
     */
    public void setIsUp(boolean isUp) {
        this.isUp = isUp;
    }

    /**
     * 获取
     *
     * @return canClick
     */
    public boolean isCanClick() {
        return canClick;
    }

    /**
     * 设置
     *
     * @param canClick
     */
    public void setCanClick(boolean canClick) {
        this.canClick = canClick;
    }

    /**
     * 获取
     *
     * @return Clicked
     */
    public boolean isClicked() {
        return Clicked;
    }

    /**
     * 设置
     *
     * @param Clicked
     */
    public void setClicked(boolean Clicked) {
        this.Clicked = Clicked;
    }

    public String toString() {
        return "Poker{name = " + name + ", isUp = " + isUp + ", canClick = " + canClick + ", Clicked = " + Clicked + "}";
    }


}
